package com.neusoft.movie.v_movies.activity;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RadioButton;

import com.neusoft.movie.v_movies.R;
import com.neusoft.movie.v_movies.fragment.MyColArtFragment;
import com.neusoft.movie.v_movies.fragment.MyColMovieFragment;
import com.neusoft.movie.v_movies.fragment.MyColUserFragment;
import com.neusoft.movie.v_movies.listener.RetrofitListener;

public class MyCollectActivity  extends BaseActivity implements RetrofitListener {

    private RecyclerView recyclerView;
    private ImageView left;
    private int u_id,collect_flag;

    protected Context context;
    private RadioButton Rbcolart;
    private RadioButton Rbcoluser;
    private RadioButton Rbcolmovie;

    private MyColMovieFragment myColMovieFragment;
    private MyColArtFragment myColArtFragment;
    private MyColUserFragment myColUserFragment;

    private FragmentManager fragmentManager;
    private FragmentTransaction transaction;
    @Override
    void initEvents() {

        left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        Rbcolart.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    myColArtFragment = new MyColArtFragment();

                    replaceFragment(myColArtFragment);
                }
            }
        });

        Rbcoluser.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    myColUserFragment = new MyColUserFragment();
                    replaceFragment(myColUserFragment);
                }
            }
        });
        Rbcolmovie.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    myColMovieFragment = new MyColMovieFragment();
                    replaceFragment(myColMovieFragment);
                }
            }
        });
        fragmentManager = getSupportFragmentManager();
        Rbcolart.setChecked(true);//设置进入此页显示的Fragment页面

    }

    @Override
    void initData() {

    }

    @Override
    void initViews() {
        setLayout(R.layout.activity_my_collect);

        left=(ImageView) findViewById(R.id.left_button);
        Rbcolart= (RadioButton) findViewById(R.id.my_col_art);
        Rbcoluser = (RadioButton) findViewById(R.id.my_col_user);
        Rbcolmovie = (RadioButton) findViewById(R.id.my_col_movie);

    }
    private void replaceFragment(Fragment fragment) {
        transaction = fragmentManager.beginTransaction();
//        Bundle bundle = new Bundle();
//        bundle.putInt("u_id", u_id);
//        fragment.setArguments(bundle);
        transaction.replace(R.id.id_daohang, fragment);
        transaction.commit();
    }


    @Override
    public void onSuccess(Object o, int flag) {


    }
    @Override
    public void onFailed() {
     //   Toast.makeText(MyColArtActivity.this, "您还没有收藏的文章", Toast.LENGTH_SHORT).show();
    }

}
